﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyCommerce.ManagementBase.Common.Base.Common;
using MyCommerce.Presentation.GeneralParameters.Presenters;
using MyCommerce.Presentation.GeneralParameters.IViews;
using Innova.Microfinanzas.BusinessEntities;

namespace MyCommerce.Windows.GeneralParameters.Views
{
    public partial class CustomerRegistrationView : BaseForm, ICustomerRegistrationView
    {
        private CustomerRegistrationPresenter pPresenter;
        public CustomerRegistrationView()
        {
            InitializeComponent();
            pPresenter = new CustomerRegistrationPresenter(this);
        }

        #region ICustomerRegistrationView Members

        public long IdCustomerLoad 
        {
            get; 
            set; 
        }

        public Customer Get()
        {
            return Customer.CreateCustomer(IdCustomerLoad, fieldName.Text, fieldIdentityCard.Text, fieldAddress.Text, fieldPhone.Text);
        }

        public void Set(Customer objCustomer)
        {
            IdCustomerLoad = objCustomer.IdCustomer;
            fieldName.Text = objCustomer.FullName;
            fieldPhone.Text = objCustomer.PhoneNumber;
            fieldAddress.Text = objCustomer.Address;
            fieldIdentityCard.Text = objCustomer.IdentityCardNumber;
        }

        public void ClearView()
        {
            IdCustomerLoad = 0;
            fieldName.Text = "";
            fieldPhone.Text = "";
            fieldAddress.Text = "";
            fieldIdentityCard.Text = "";
        }

        public void SetWindowResult(object result)
        {            
            Result = result;
            Close();
        }

        public event EventHandler OnSave;
        public event EventHandler OnCancel;

        #endregion

        private void tsCancelButtonToolStrip_Click(object sender, EventArgs e)
        {
            if (OnCancel != null)
                OnCancel(this, new EventArgs());
        }

        private void tsSaveButtonToolStrip_Click(object sender, EventArgs e)
        {
            if (OnSave != null)
                OnSave(this, new EventArgs());
        }

        private void CustomerRegistrationView_Load(object sender, EventArgs e)
        {
            if (Parameter != null)
                Set((Customer)Parameter);
        }
    }
}
